
#include "VarArray.hpp"
// #include
/**
 * @brief 计算三对角矩阵
 *    详细见 数值分析 p75 车刚明
 * @param coefficient_matrix 3×n 系数矩阵
 * @param value 进入是fx  返回为 解
 * @param end 最后一个值的下一个
 * @param begin 起始
 */
void ThomasAlgorithm(VarArray<double, 2, 0> &coefficient_matrix, double *value,
                     int begin, int end) {

  for (int i = begin + 1; i < end; ++i) {
    coefficient_matrix(0, i) =
        coefficient_matrix(0, i) / coefficient_matrix(1, i - 1);
    coefficient_matrix(1, i) =
        coefficient_matrix(1, i) -
        coefficient_matrix(0, i) * coefficient_matrix(2, i - 1);

    value[i] = value[i] - coefficient_matrix(0, i) * value[i - 1];
  }

  // PrintForCheck(coefficient_matrix);
  value[end - 1] = value[end - 1] / coefficient_matrix(1, end - 1);
  for (int i = end - 2; i > begin - 1; --i) {
    value[i] = (value[i] - coefficient_matrix(2, i) * value[i + 1]) /
               coefficient_matrix(1, i);
  }
}
